﻿using AiMoWindows.CodeScripts;
using AiMoWindows.CodeScripts.IO;
using AiMoWindows.MainActions.Mode;
using System.IO;

namespace AiMoWindows.MainActions.LibraryActions.ExampleItems
{
    class LibraryExampleItem
    {
        public string Name { get; }
        public ScriptSource Script { get; }
        public LibraryExampleItem(ScriptComplileMode mode, string name, string usings = "", string mains = "", string functions = "", string classes = "", string descriptions = "")
        {
            Name = name;
            Script = new ScriptSource(mode, null, true);
            Script.SetUsingCode(usings);
            if (!string.IsNullOrEmpty(mains)) Script.MainCode.UpdateLines(mains);
            if (!string.IsNullOrEmpty(functions)) Script.MainCode.UpdateLines(functions);
            if (!string.IsNullOrEmpty(classes)) Script.MainCode.UpdateLines(classes);
            Script.SetAuthorAndDescription("AiMo Default Examples 2024.07.18", descriptions);
        }
        public void WriteToFile(DirectoryInfo directory)
        {
            string fileName = Path.Combine(directory.FullName, Name);
            byte[] bytes = CodeIO.GetBytes(Script, true);
            File.WriteAllBytes(fileName, bytes);
        }
    }
}
